class Solution {
    public int longestOnes(int[] nums, int k) {
        int zero = 0;
        int left = 0;
        int ans = 0;
        for(int i = 0 ; i < nums.length;i++){
            if(nums[i] == 0)zero += 1;
            while(zero > k){
                if(nums[left] == 0)zero -= 1;
                left += 1;
            }
            ans = Math.max(ans,i - left + 1);
        }return ans;

    }
}